package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@Table(name = "PRODUCT_GROUP")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductGroup implements Serializable {

    private static final long serialVersionUID = 1684006081786077252L;

    @Id
    @Column(name = "GROUP_ID")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "PRODUCT_GROUP_SEQ")
    @SequenceGenerator(name = "PRODUCT_GROUP_SEQ", allocationSize = 1, sequenceName = "PRODUCT_GROUP_SEQ")
    private Long groupId;

    /**
     *  产品组名称
     */
    @Column(name = "GROUP_NAME")
    private String groupName;

    /**
     *  状态   0：以发布  1:以撤回  2:待发布
     */
    @Column(name = "STATUS")
    private String status;

    /**
     *  别名
     */
    @Column(name = "ALIAS")
    private String alias;

    /**
     *   创建时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="CREATE_TIME")
    private java.time.LocalDateTime createTime;

    /**
     *   更新时间
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="UPDATE_TIME")
    private java.time.LocalDateTime updateTime;

    public static void putTimeAndUser(ProductGroup productGroup){
        if(productGroup.getGroupId()==null){
            productGroup.setCreateTime(java.time.LocalDateTime.now());
        }
        productGroup.setUpdateTime(java.time.LocalDateTime.now());

    }
}
